/** 
 * Copyright (C), 2010-2012, AIYOU Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:UserAttentionGroupServiceImp.java
 * Version:1.0
 * Date:Dec 10, 2011
 * Description: 
 * author:whh
 */
package com.tietiao.service.userattentiongroup;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tietiao.common.constants.LogConstants;
import com.tietiao.dao.UserAttentionGroupMapper;
import com.tietiao.dao.model.UserAttentionGroup;
import com.tietiao.dao.model.UserAttentionGroupCriteria;
import com.tietiao.service.miduserattention.MidUserAttentionService;
import com.tietiao.service.syslog.SysLogService;
@Service
@Transactional
public class UserAttentionGroupServiceImp implements UserAttentionGroupService {
	@Resource
	private UserAttentionGroupMapper userAttentionGroupMapper;
	@Resource
	private MidUserAttentionService midUserAttentionService;
	@Resource
	private SysLogService sysLogService;
	/* (non-Javadoc)
	 * @see com.tietiao.service.userattentiongroup.UserAttentionGroupService#deleteUserAttentionGroup(int)
	 */
	public int deleteUserAttentionGroup(int id) {
		sysLogService.insertSysLog(LogConstants.OP_TYPE_INSERT, "好友分组", "删除的好友组ID为："+id);		
		midUserAttentionService.modifyUserAttentionToDefaultGroup(id);
		return userAttentionGroupMapper.deleteByPrimaryKey(id);
	}

	/* (non-Javadoc)
	 * @see com.tietiao.service.userattentiongroup.UserAttentionGroupService#getUserAttentionGroup(int)
	 */
	@Override
	public List<UserAttentionGroup> getUserAttentionGroup(int userId) {
		UserAttentionGroupCriteria userAttentionGroupCriteria = new UserAttentionGroupCriteria();
		UserAttentionGroupCriteria.Criteria  criteria = userAttentionGroupCriteria.createCriteria();

		criteria.andUserIdEqualTo(userId);
		userAttentionGroupCriteria.setOrderByClause(" sort ,create_time ");
		return userAttentionGroupMapper.selectByExample(userAttentionGroupCriteria);
	}

	/* (non-Javadoc)
	 * @see com.tietiao.service.userattentiongroup.UserAttentionGroupService#insertUserAttentionGroup(com.tietiao.dao.model.UserAttentionGroup)
	 */
	@Override
	public int insertUserAttentionGroup(UserAttentionGroup group) {
		sysLogService.insertSysLog(LogConstants.OP_TYPE_INSERT, "添加好友分组", group.getGroupName());		
		userAttentionGroupMapper.insert(group);
		
		return group.getGroupId();
	}

	/* (non-Javadoc)
	 * @see com.tietiao.service.userattentiongroup.UserAttentionGroupService#updateUserAttentionGroup(com.tietiao.dao.model.UserAttentionGroup)
	 */
	@Override
	public int updateUserAttentionGroup(UserAttentionGroup group) {
		sysLogService.insertSysLog(LogConstants.OP_TYPE_UPDATE, "更新好友分组", group.getGroupName());	
		return userAttentionGroupMapper.updateByPrimaryKey(group);
	}

}
